package com.ruoyi.web.core.config;

import com.ruoyi.accountant.job.CleanJob;
import com.ruoyi.accountant.job.DepreciationDeviceJob;
import com.ruoyi.accountant.job.InaccountJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 定时任务配置
 */
@Configuration
public class QuartzConf {
    @Bean
    public JobDetail clean() {
        return JobBuilder.newJob(CleanJob.class).storeDurably().build();
    }

    @Bean
    public JobDetail inaccount() {
        return JobBuilder.newJob(InaccountJob.class).storeDurably().build();
    }

    @Bean
    public JobDetail deprecatedDevice() {
        return JobBuilder.newJob(DepreciationDeviceJob.class).storeDurably().build();
    }

    /***
     * 清理数据任务，每天1点执行一次
     * @return
     */
    @Bean
    public Trigger backupTrigger() {
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("1 1 1 * * ?");
        return TriggerBuilder.newTrigger().forJob(clean()).withIdentity("cleanJob").withSchedule(cronScheduleBuilder).build();
    }

    /***
     * 入账任务，每天2点执行一次
     * @return
     */
    @Bean
    public Trigger inaccountTrigger() {
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("1 1 2 * * ?");
        return TriggerBuilder.newTrigger().forJob(inaccount()).withIdentity("inaccountJob").withSchedule(cronScheduleBuilder).build();
    }

    /***
     * 折旧设备，每月1号3点执行一次
     * @return
     */
    @Bean
    public Trigger deprecatedDeviceTrigger() {
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("1 1 3 1 1-12 ?");
        return TriggerBuilder.newTrigger().forJob(deprecatedDevice()).withIdentity("deprecatedDeviceJob").withSchedule(cronScheduleBuilder).build();
    }
}
